package com.linkage.jz.bankruptcy.activity.Project;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.RegistLogin.AccountLoginActivity;
import com.linkage.jz.bankruptcy.bean.ManagerUserInfo;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.seapeak.base.BaseWhiteActivity;
import com.linkage.seapeak.utils.ToastUtil;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


public class ProjectPermissionActivity extends BaseWhiteActivity {
    private static final String TAG = AccountLoginActivity.class.getSimpleName();

    TextView select_all;

    private MyProInfo mInfo;
    private CheckBox proXm;
    private CheckBox proJd;
    private CheckBox proZq;
    private CheckBox proBj;
    private CheckBox proTl;
    private CheckBox proRw;
    private CheckBox proGs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prouser_permission, "设置公开栏目");
        String bookJson = getIntent().getStringExtra("info");
        mInfo = new Gson().fromJson(bookJson, MyProInfo.class);
        initView();
    }

    private void initView() {
        proXm = (CheckBox) findViewById(R.id.pro_xm);
        proJd = (CheckBox) findViewById(R.id.pro_jd);
        proZq = (CheckBox) findViewById(R.id.pro_zq);
        proBj = (CheckBox) findViewById(R.id.pro_bj);
        proTl = (CheckBox) findViewById(R.id.pro_tl);
        proRw = (CheckBox) findViewById(R.id.pro_rw);
        proGs = (CheckBox) findViewById(R.id.pro_gs);

        select_all = findViewById(R.id.select_all);
        select_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                proXm.setChecked(true);
                proJd.setChecked(true);
                proZq.setChecked(true);
                proBj.setChecked(true);
                proTl.setChecked(true);
                proRw.setChecked(true);
                proGs.setChecked(true);
            }
        });

        String column = mInfo.getPublicSection();
        proXm.setChecked(column.contains("0"));
        proJd.setChecked(column.contains("1"));
        proZq.setChecked(column.contains("2"));
        proBj.setChecked(column.contains("3"));
        proTl.setChecked(column.contains("4"));
        proRw.setChecked(column.contains("5"));
        proGs.setChecked(column.contains("6"));

        addMenu(new MenuAction(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str = "";
                str += proXm.isChecked() ? ",0" : "";
                str += proJd.isChecked() ? ",1" : "";
                str += proZq.isChecked() ? ",2" : "";
                str += proBj.isChecked() ? ",3" : "";
                str += proTl.isChecked() ? ",4" : "";
                str += proRw.isChecked() ? ",5" : "";
                str += proGs.isChecked() ? ",6" : "";
                if (!TextUtils.isEmpty(str))
                    str = str.substring(1);

                Intent intent = new Intent();
                intent.putExtra("section", str);
                setResult(RESULT_OK, intent);
                finish();
            }
        }, "完成", 0));
    }


}
